#include <curl/curl.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

FILE *fp = NULL;
int write_data(void *ptr, size_t size, size_t nmemb, void *stream)
{
	return fwrite(ptr, size, nmemb, (FILE *)fp);
}

int main(int argc, char **argv)
{
	const char *path = "/tmp/curl_test.html";
	const char *mode = "w";

	fp = fopen(path, mode);
	curl_global_init(CURL_GLOBAL_ALL);

	CURLcode res;
	CURL *curl = curl_easy_init();
	curl_easy_setopt(curl, CURLOPT_URL, "http://blog.chinaunix.net/uid/24467128.html");
	curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);
	curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);
	res = curl_easy_perform(curl);
	curl_easy_cleanup(curl);

	return 0;
}
